//
//  AppDelegate.swift
//  XinlangWeibo
//
//  Created by yangyinglei on 2017/3/26.
//  Copyright © 2017年 yangyinglei. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        //接收通知
        NotificationCenter.default.addObserver(self, selector: #selector(switchRootVC(noti:)), name: NSNotification.Name(rawValue: SwitchRootVCNotification), object: nil)
        //获取用户信息
        let userAccount = YYLUserAccountViewModel.shareViewModel.userAccount
        print(userAccount )
        
        window = UIWindow(frame: UIScreen.main.bounds)

        window?.rootViewController = YYLWellcomeViewController()
        window?.backgroundColor = UIColor.white
        window?.makeKeyAndVisible()
        
        return true
    }

    //  响应通知的事件
    @objc private func switchRootVC(noti: NSNotification) {
        let obj = noti.object
        if obj is YYLOAuthViewController {
        window?.rootViewController = YYLWellcomeViewController()
        
        } else {
        window?.rootViewController = YYLMainViewController()
        
        }
        
    }
    
    //最好匹配取消监听  在析构函数中移除
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
}

